package com.zrrd.mcl.product.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zrrd.mcl.common.result.Result;
import com.zrrd.mcl.model.product.BaseTrademark;
import com.zrrd.mcl.product.service.TrademarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product/baseTrademark")
public class TrademarkController {

    @Autowired
    private TrademarkService trademarkService;

    @GetMapping("/getTrademarkList")
    public Result<List<BaseTrademark>> baseSaleAttrList() {
        return Result.ok(trademarkService.list(null));
    }

    @GetMapping("/{page}/{limit}")
    public Result<Page<BaseTrademark>> page(@PathVariable int page, @PathVariable int limit) {
        Page<BaseTrademark> pageInfo = new Page<>(page, limit);
        QueryWrapper<BaseTrademark> wrapper = new QueryWrapper<>();
        trademarkService.page(pageInfo, wrapper);
        return Result.ok(pageInfo);
    }

    //保存品牌
    @PostMapping("/save")
    public Result<String> saveTrademark(@RequestBody BaseTrademark baseTrademark) {
        trademarkService.save(baseTrademark);
        return Result.ok("成功");
    }

    //修改品牌
    @PutMapping("/update")
    public Result<String> updateTrademark(@RequestBody BaseTrademark baseTrademark) {
        trademarkService.updateById(baseTrademark);
        return Result.ok("成功");
    }

    //展示品牌
    @GetMapping("/get/{id}")
    public Result<BaseTrademark> list(@PathVariable("id") Long id) {
        BaseTrademark baseTrademark = trademarkService.getById(id);
        return Result.ok(baseTrademark);
    }

    //删除品牌
    @DeleteMapping("/baseTrademark/remove/{id}")
    public Result<String> removeTrademark(@PathVariable("id") Long id) {
        trademarkService.removeById(id);
        return Result.ok("成功");
    }
}
